// exports.AL_Framework_UI_Manager = exports.ViewDynamicLoadData = exports.ViewStatus = void 0;
// var i;
// var n;
// var $macros = require("./AL_Framework_Macros");
// var $resource = require("./AL_Framewrok_Resource");
// (n = i = exports.ViewStatus || (exports.ViewStatus = {}))[(n.WAITTING_CLOSE = 0)] = "WAITTING_CLOSE";
// n[(n.WATITING_HIDE = 1)] = "WATITING_HIDE";
// n[(n.WAITTING_NONE = 2)] = "WAITTING_NONE";
// var r = "DYNAMIC_LOAD_GARBAGE";
// var c = (function () {
//     function e(e) {
//         if (void 0 === e) {
//             e = null;
//         }
//         this.local = new Map();
//         this.remote = new Map();
//         this.name = e;
//     }
//     e.prototype.tianjia_bendi = function (e, t) {
//         if (void 0 === t) {
//             t = null;
//         }
//         if (e && e.url) {
//             if (this.name == r) {
//                 Log.e("找不到资源持有者: " + e.url);
//             }
//             if (!this.local.has(e.url)) {
//                 Manager.assetManager.retainAsset(e);
//                 this.local.set(e.url, e);
//             }
//         }
//     };
//     e.prototype.tianjia_yuancheng = function (e, t) {
//         if (void 0 === t) {
//             t = null;
//         }
//         if (e && e.data && !this.remote.has(e.url)) {
//             if (this.name == r) {
//                 Log.e("找不到资源持有者 : " + e.url);
//             }
//             Manager.cacheManager.remote_Caches.retainAsset(e);
//             this.remote.set(e.url, e);
//         }
//     };
//     e.prototype.clear = function () {
//         this.name == r
//             ? ((this.local.size > 0 || this.remote.size > 0) && Log.e("当前未能释放资源如下:"),
//               this.local &&
//                   this.local.size > 0 &&
//                   (Log.e("-----------local-----------"),
//                   this.local &&
//                       this.local.forEach(function (e) {
//                           Log.e(e.url);
//                       })),
//               this.remote &&
//                   this.remote.size > 0 &&
//                   (Log.e("-----------remote-----------"),
//                   this.remote &&
//                       this.remote.forEach(function (e) {
//                           Log.e(e.url);
//                       })))
//             : (this.local &&
//                   (this.local.forEach(function (e) {
//                       Manager.assetManager.releaseAsset(e);
//                   }),
//                   this.local.clear()),
//               this.remote &&
//                   (this.remote.forEach(function (e) {
//                       Manager.cacheManager.remote_Caches.releaseAsset(e);
//                   }),
//                   this.remote.clear()));
//     };
//     return e;
// })();
// exports.ViewDynamicLoadData = c;
// var l = (function () {
//     function e() {
//         this.isLoaded = !1;
//         this.status = i.WAITTING_NONE;
//         this.view = null;
//         this.finishCb = [];
//         this.getViewCb = [];
//         this.isPreload = !1;
//         this.isPrefab = !0;
//         this.info = null;
//         this.viewType = null;
//         this.bundle = null;
//         this.loadData = new c();
//         this.node = null;
//     }
//     e.prototype.zhixing_huoqu = function (e) {
//         for (var t = 0; t < this.getViewCb.length; t++) {
//             var o = this.getViewCb[t];
//             if (o) {
//                 o(e);
//             }
//         }
//         this.getViewCb = [];
//     };
//     e.prototype.zhixing_wancheng = function (e) {
//         for (var t = 0; t < this.finishCb.length; t++) {
//             var o = this.finishCb[t];
//             if (o) {
//                 o(e);
//             }
//         }
//         this.finishCb = [];
//     };
//     e.prototype.zhixing_suoyou_huidiao = function (e, t, o) {
//         this.zhixing_wancheng(e, t, o);
//         this.zhixing_huoqu(e, t, o);
//     };
//     return e;
// })();
// var d = (function () {
//     function e() {
//         this._logTag = "[AL_Framework_UI_Manager]";
//         this._viewDatas = new Map();
//         this.garbage = new c(r);
//         this.retainMemory = new c("DYNAMIC_LOAD_RETAIN_MEMORY");
//         this._canvas = null;
//         this._componentRoot = null;
//         this._mainController = null;
//         this._prefabs = null;
//     }
//     e.Instance = function () {
//         return this._instance || (this._instance = new e());
//     };
//     e.prototype.huoqu_shitu_shuju = function (e) {
//         var t = this.getClassName(e);
//         if (t) {
//             return this._viewDatas.has(t) ? this._viewDatas.get(t) : void 0;
//         }
//     };
//     e.prototype.huoqu_shitu_leixing = function (e) {
//         if (!cc.isValid(e)) {
//             return null;
//         }
//         var t = e.className;
//         if (!t) {
//             return null;
//         }
//         var o = this._viewDatas.get(t);
//         return o ? o.viewType : null;
//     };
//     e.prototype.getClassName = function (e) {
//         if (e) {
//             return "string" == typeof e ? e : cc.js.getClassName(e);
//         }
//     };
//     e.prototype.moren_dakai_xuanxiang = function (e) {
//         var t = {
//             bundle: $macros.Macro.BUNDLE_RESOURCES,
//             url: e.url,
//             delay: e.delay,
//             name: e.name,
//             zIndex: 0,
//             preload: !1,
//             type: e.type,
//             args: e.args,
//             showLoading: e.showLoading,
//             showUILoading: e.showUILoading,
//             shifou_yanchi_shifang_ziyuan: !0
//         };
//         if (null != e.bundle) {
//             t.bundle = e.bundle;
//         }
//         if (null != e.zIndex) {
//             t.zIndex = e.zIndex;
//         }
//         if (null != e.preload) {
//             t.preload = e.preload;
//         }
//         if (null != e.shifou_yanchi_shifang_ziyuan) {
//             t.shifou_yanchi_shifang_ziyuan = e.shifou_yanchi_shifang_ziyuan;
//         }
//         return t;
//     };
//     e.prototype.preload = function (e, t, o) {
//         return this.open({
//             type: e,
//             preload: !0,
//             bundle: t,
//             url: o
//         });
//     };
//     e.prototype.jiexi_yuzhiti_url = function (e) {
//         return "@" == e[0]
//             ? {
//                   isPrefab: !1,
//                   url: e.substr(1)
//               }
//             : {
//                   isPrefab: !0,
//                   url: e
//               };
//     };
//     e.prototype.open = function (e) {
//         var t = this.moren_dakai_xuanxiang(e);
//         return this._open(t);
//     };
//     e.prototype._open = function (e) {
//         var t = this;
//         return new Promise(function (o) {
//             if (e.type) {
//                 var n = cc.js.getClassName(e.type);
//                 if (t.shitu_genjiedian) {
//                     var a = t.huoqu_shitu_shuju(e.type);
//                     if (a) {
//                         a.isPreload = e.preload;
//                         a.info.shifou_yanchi_shifang_ziyuan = e.shifou_yanchi_shifang_ziyuan;
//                         return a.isLoaded
//                             ? ((a.status = i.WAITTING_NONE),
//                               e.preload ||
//                                   (a.view &&
//                                       cc.isValid(a.node) &&
//                                       ((a.node.zIndex = e.zIndex),
//                                       (a.node.active = !0),
//                                       a.node.parent || t.tianjia_shitu(a.node, e.zIndex),
//                                       (a.view.params = e),
//                                       a.view.show(e.args))),
//                               void o(a.view))
//                             : ((a.status = i.WAITTING_NONE),
//                               e.preload ||
//                                   (e.showLoading
//                                       ? Manager.loading.show()
//                                       : e.showUILoading &&
//                                         Manager.ui_Loading.show({
//                                             uiName: e.name,
//                                             delay: e.delay
//                                         })),
//                               void a.finishCb.push(o));
//                     }
//                     (a = new l()).loadData.name = n;
//                     var r = e.url || e.type.huoqu_yuzhiti_url();
//                     if (r) {
//                         var c = t.jiexi_yuzhiti_url(r);
//                         a.isPreload = e.preload;
//                         a.isPrefab = c.isPrefab;
//                         a.viewType = e.type;
//                         a.bundle = e.bundle;
//                         t._viewDatas.set(n, a);
//                         if (!c.isPrefab) {
//                             a.info = new $resource.AL_Framewrok_Resource.Info();
//                             a.info.url = c.url;
//                             a.info.type = cc.Prefab;
//                             a.info.data = t.huoqu_changjing_yuzhiti(c.url);
//                             a.info.bundle = e.bundle;
//                             a.info.shifou_yanchi_shifang_ziyuan = e.shifou_yanchi_shifang_ziyuan;
//                             return void t.chuangjian_jiedian(a, o, e);
//                         }
//                         var d = null;
//                         if (!e.preload) {
//                             e.showLoading
//                                 ? Manager.loading.show()
//                                 : e.showUILoading &&
//                                   (Manager.ui_Loading.show({
//                                       uiName: e.name,
//                                       delay: e.delay
//                                   }),
//                                   (d = function (e, t) {
//                                       var o = Math.ceil((e / t) * 100);
//                                       Manager.ui_Loading.gengxin_jindu(o);
//                                   }));
//                         }
//                         t.jiazai_yuzhiti(e.bundle, r, d)
//                             .then(function (i) {
//                                 a.info = new $resource.AL_Framewrok_Resource.Info();
//                                 a.info.url = r;
//                                 a.info.type = cc.Prefab;
//                                 a.info.data = i;
//                                 a.info.bundle = e.bundle;
//                                 if ("boolean" == typeof e.shifou_yanchi_shifang_ziyuan) {
//                                     a.info.shifou_yanchi_shifang_ziyuan = e.shifou_yanchi_shifang_ziyuan;
//                                 }
//                                 Manager.assetManager.retainAsset(a.info);
//                                 t.chuangjian_jiedian(a, o, e);
//                                 if (e.showLoading) {
//                                     Manager.loading.hide();
//                                 }
//                                 if (e.showUILoading) {
//                                     Manager.ui_Loading.hide();
//                                 }
//                             })
//                             .catch(function (i) {
//                                 a.isLoaded = !0;
//                                 Log.e(i);
//                                 t.close(e.type);
//                                 a.zhixing_suoyou_huidiao(null, n, "打开界面异常");
//                                 o(null);
//                                 if (e.name) {
//                                     e.name;
//                                 }
//                                 if (e.showUILoading) {
//                                     Manager.ui_Loading.hide();
//                                 }
//                                 if (e.showLoading) {
//                                     Manager.loading.hide();
//                                 }
//                             });
//                     } else {
//                         o(null);
//                     }
//                 } else {
//                     o(null);
//                 }
//             } else {
//                 o(null);
//             }
//         });
//     };
//     e.prototype._tianjia_zujian = function (e, t, o) {
//         if (e) {
//             var i = this.getClassName(t.viewType);
//             var n = e.getComponent(t.viewType);
//             return n || (n = e.addComponent(t.viewType))
//                 ? ((n.className = i),
//                   (n.bundle = o.bundle),
//                   (t.view = n),
//                   (n.args = o.args),
//                   t.isPreload || this.tianjia_shitu(e, o.zIndex),
//                   n)
//                 : null;
//         }
//         return null;
//     };
//     e.prototype.chuangjian_jiedian = function (e, t, o) {
//         e.isLoaded = !0;
//         var n = this.getClassName(e.viewType);
//         if (e.status == i.WAITTING_CLOSE) {
//             t(null);
//             return void e.zhixing_suoyou_huidiao(null, n, "获取界内已经关闭");
//         }
//         if (e.info.data instanceof cc.Node) {
//             e.info.data.active = !1;
//         }
//         var a = cc.instantiate(e.info.data);
//         a.active = !0;
//         e.node = a;
//         var s = this._tianjia_zujian(a, e, o);
//         s
//             ? e.status == i.WATITING_HIDE
//                 ? (s.hide(), t(s), e.zhixing_suoyou_huidiao(s, n, "加载完成，但加载过程中被隐藏"))
//                 : (e.isPreload || ((s.params = o), s.show(o.args)),
//                   t(s),
//                   e.zhixing_suoyou_huidiao(s, n, "加载完成，回调之前加载中的界面"))
//             : t(null);
//     };
//     e.prototype.jiazai_yuzhiti = function (e, t, o) {
//         return new Promise(function (i, n) {
//             Manager.assetManager.load({
//                 bundle: e,
//                 path: t,
//                 type: cc.Prefab,
//                 onProgress: o,
//                 onComplete: function (e) {
//                     e && e.data && e.data instanceof cc.Prefab ? i(e.data) : n("加载prefab : " + t + " 失败");
//                 }
//             });
//         });
//     };
//     Object.defineProperty(e.prototype, "shitu_genjiedian", {
//         get: function () {
//             return cc.Canvas.instance.node;
//         },
//         enumerable: !1,
//         configurable: !0
//     });
//     Object.defineProperty(e.prototype, "componentRoot", {
//         get: function () {
//             if (!(this._componentRoot || cc.isValid(this._componentRoot))) {
//                 this._componentRoot = cc.find("componentRoot", this.canvas);
//             }
//             return this._componentRoot;
//         },
//         enumerable: !1,
//         configurable: !0
//     });
//     Object.defineProperty(e.prototype, "mainController", {
//         get: function () {
//             if (!this._mainController && !cc.isValid(this._mainController)) {
//                 return this._mainController;
//             }
//             var e = this.canvas;
//             return e ? ((this._mainController = e.getComponent("MainController")), this._mainController) : null;
//         },
//         enumerable: !1,
//         configurable: !0
//     });
//     Object.defineProperty(e.prototype, "prefabs", {
//         get: function () {
//             if (!(this._prefabs || cc.isValid(this._prefabs))) {
//                 this._prefabs = cc.find("prefabs", this.canvas);
//             }
//             return this._prefabs;
//         },
//         enumerable: !1,
//         configurable: !0
//     });
//     e.prototype.huoqu_changjing_yuzhiti = function (e) {
//         return cc.find(e);
//     };
//     e.prototype.onLoad = function (e) {
//         this._canvas = e;
//     };
//     Object.defineProperty(e.prototype, "canvas", {
//         get: function () {
//             return this._canvas;
//         },
//         enumerable: !1,
//         configurable: !0
//     });
//     e.prototype.tianjia_shitu = function (e, t) {
//         this.shitu_genjiedian.addChild(e);
//         if ("number" == typeof t) {
//             e.zIndex = t;
//         }
//     };
//     e.prototype.tianjia_bendi = function (e, t) {
//         if (e) {
//             var o = this.huoqu_shitu_shuju(t);
//             if (o) {
//                 o.loadData.tianjia_bendi(e, t);
//             }
//         }
//     };
//     e.prototype.tianjia_yuancheng = function (e, t) {
//         if (e) {
//             var o = this.huoqu_shitu_shuju(t);
//             if (o) {
//                 o.loadData.tianjia_yuancheng(e, t);
//             }
//         }
//     };
//     e.prototype.close = function (e) {
//         var t = this.huoqu_shitu_shuju(e);
//         if (t) {
//             t.status = i.WAITTING_CLOSE;
//             if (t.view && cc.isValid(t.node)) {
//                 t.node.removeFromParent();
//                 t.node.destroy();
//             }
//             this.chuli_ui_xiaohui(e);
//         }
//     };
//     e.prototype.chuli_ui_xiaohui = function (e) {
//         var t = this.huoqu_shitu_shuju(e);
//         if (t) {
//             var o = this.getClassName(e);
//             t.loadData.clear();
//             t.isPrefab;
//             this._viewDatas.delete(o);
//             Log.d(this._logTag + " close view : " + o);
//         }
//     };
//     e.prototype.close_Except = function (e) {
//         var t = this;
//         if (null != e && null != e && 0 != e.length) {
//             var o = new Set();
//             for (var i = 0; i < e.length; i++) {
//                 o.add(this.getClassName(e[i]));
//             }
//             this._viewDatas.forEach(function (e, i) {
//                 if (!o.has(i)) {
//                     t.close(i);
//                 }
//             });
//         } else {
//             this._viewDatas.forEach(function (e, o) {
//                 t.close(o);
//             });
//         }
//     };
//     e.prototype.close_Bundle_View = function (e) {
//         var t = this;
//         this._viewDatas.forEach(function (o, i) {
//             if (o.bundle == e) {
//                 t.close(i);
//             }
//         });
//     };
//     e.prototype.hide = function (e) {
//         var t = this.huoqu_shitu_shuju(e);
//         if (t) {
//             t.isLoaded ? t.view && cc.isValid(t.view.node) && t.view.hide() : (t.status = i.WATITING_HIDE);
//         }
//     };
//     e.prototype.huoqu_shitu = function (e) {
//         var t = this;
//         return new Promise(function (o) {
//             if (null != e && null != e) {
//                 var i = t.huoqu_shitu_shuju(e);
//                 i ? (i.isPreload ? o(null) : i.isLoaded ? o(i.view) : i.getViewCb.push(o)) : o(null);
//             } else {
//                 o(null);
//             }
//         });
//     };
//     e.prototype.jiancha_shitu = function () {};
//     e.prototype.isShow = function (e) {
//         var t = this.huoqu_shitu_shuju(e);
//         return !!t && !(!t.isLoaded || t.status != i.WAITTING_NONE || !t.view) && t.view.node.active;
//     };
//     e.prototype.addComponent = function (e) {
//         var t = this.componentRoot;
//         return t ? t.getComponent(e) || t.addComponent(e) : null;
//     };
//     e.prototype.removeComponent = function (e) {
//         var t = this.componentRoot;
//         if (t) {
//             var o = t.getComponent(e);
//             if (o) {
//                 o.destroy();
//             }
//         }
//     };
//     e.prototype.print = function (e) {
//         if (e) {
//             var t;
//             if (e.printViews) {
//                 this._viewDatas.forEach(function (t, o) {
//                     if (e.printViews) {
//                         e.printViews(t, o);
//                     }
//                 });
//             }
//             if (e.printChildren && (t = this.shitu_genjiedian)) {
//                 var o = t.children;
//                 for (var i = 0; i < o.length; i++) {
//                     e.printChildren(o[i]);
//                 }
//             }
//             if (e.printComp && (t = this.componentRoot)) {
//                 var n = t._components;
//                 for (i = 0; i < n.length; i++) {
//                     e.printComp(n[i]);
//                 }
//             }
//         }
//     };
//     e._instance = null;
//     return e;
// })();
// exports.AL_Framework_UI_Manager = d;


const $macros = require("./AL_Framework_Macros");
const $resource = require("./AL_Framewrok_Resource");

var ViewStatus;
(function (ViewStatus) {
    ViewStatus[ViewStatus["WAITTING_CLOSE"] = 0] = "WAITTING_CLOSE";
    ViewStatus[ViewStatus["WATITING_HIDE"] = 1] = "WATITING_HIDE";
    ViewStatus[ViewStatus["WAITTING_NONE"] = 2] = "WAITTING_NONE";
})(ViewStatus = exports.ViewStatus || (exports.ViewStatus = {}));

const DYNAMIC_LOAD_GARBAGE = "DYNAMIC_LOAD_GARBAGE";

/**
 * @class ViewDynamicLoadData
 * 视图动态加载数据类
 */
class ViewDynamicLoadData {
    constructor(name = null) {
        this.local = new Map();
        this.remote = new Map();
        this.name = name;
    }

    /**
     * 添加本地资源
     * @param {object} asset - 资源对象
     * @param {object|null} owner - 资源持有者
     */
    tianjia_bendi(asset, owner = null) {
        if (asset && asset.url) {
            if (this.name === DYNAMIC_LOAD_GARBAGE) {
                Log.e("找不到资源持有者: " + asset.url);
            }
            if (!this.local.has(asset.url)) {
                Manager.assetManager.retainAsset(asset);
                this.local.set(asset.url, asset);
            }
        }
    }

    /**
     * 添加远程资源
     * @param {object} asset - 资源对象
     * @param {object|null} owner - 资源持有者
     */
    tianjia_yuancheng(asset, owner = null) {
        if (asset && asset.data && !this.remote.has(asset.url)) {
            if (this.name === DYNAMIC_LOAD_GARBAGE) {
                Log.e("找不到资源持有者 : " + asset.url);
            }
            Manager.cacheManager.remote_Caches.retainAsset(asset);
            this.remote.set(asset.url, asset);
        }
    }

    /**
     * 清除所有资源
     */
    clear() {
        if (this.name === DYNAMIC_LOAD_GARBAGE) {
            if (this.local.size > 0 || this.remote.size > 0) {
                Log.e("当前未能释放资源如下:");
                if (this.local.size > 0) {
                    Log.e("-----------local-----------");
                    this.local.forEach(asset => Log.e(asset.url));
                }
                if (this.remote.size > 0) {
                    Log.e("-----------remote-----------");
                    this.remote.forEach(asset => Log.e(asset.url));
                }
            }
        } else {
            this.local.forEach(asset => Manager.assetManager.releaseAsset(asset));
            this.local.clear();
            this.remote.forEach(asset => Manager.cacheManager.remote_Caches.releaseAsset(asset));
            this.remote.clear();
        }
    }
}

exports.ViewDynamicLoadData = ViewDynamicLoadData;

/**
 * @class ViewData
 * 视图数据类
 */
class ViewData {
    constructor() {
        this.isLoaded = false;
        this.status = ViewStatus.WAITTING_NONE;
        this.view = null;
        this.finishCb = [];
        this.getViewCb = [];
        this.isPreload = false;
        this.isPrefab = true;
        this.info = null;
        this.viewType = null;
        this.bundle = null;
        this.loadData = new ViewDynamicLoadData();
        this.node = null;
    }

    /**
     * 执行获取视图回调
     * @param {object} view - 视图对象
     */
    zhixing_huoqu(view) {
        this.getViewCb.forEach(cb => cb && cb(view));
        this.getViewCb = [];
    }

    /**
     * 执行完成回调
     * @param {object} view - 视图对象
     */
    zhixing_wancheng(view) {
        this.finishCb.forEach(cb => cb && cb(view));
        this.finishCb = [];
    }

    /**
     * 执行所有回调
     * @param {object} view - 视图对象
     * @param {string} className - 类名
     * @param {string} message - 消息
     */
    zhixing_suoyou_huidiao(view, className, message) {
        this.zhixing_wancheng(view, className, message);
        this.zhixing_huoqu(view, className, message);
    }
}

/**
 * @class AL_Framework_UI_Manager
 * UI管理器类
 */
class AL_Framework_UI_Manager {
    constructor() {
        this._logTag = "[AL_Framework_UI_Manager]";
        this._viewDatas = new Map();
        this.garbage = new ViewDynamicLoadData(DYNAMIC_LOAD_GARBAGE);
        this.retainMemory = new ViewDynamicLoadData("DYNAMIC_LOAD_RETAIN_MEMORY");
        this._canvas = null;
        this._componentRoot = null;
        this._mainController = null;
        this._prefabs = null;
    }

    static Instance() {
        if (!this._instance) {
            this._instance = new AL_Framework_UI_Manager();
        }
        return this._instance;
    }

    /**
     * 获取视图数据
     * @param {string|object} type - 视图类型
     * @returns {ViewData|undefined} - 视图数据
     */
    huoqu_shitu_shuju(type) {
        const className = this.getClassName(type);
        if (className && this._viewDatas.has(className)) {
            return this._viewDatas.get(className);
        }
        return undefined;
    }

    /**
     * 获取视图类型
     * @param {cc.Node} node - 节点
     * @returns {string|null} - 视图类型
     */
    huoqu_shitu_leixing(node) {
        if (!cc.isValid(node)) {
            return null;
        }
        const className = node.className;
        if (!className) {
            return null;
        }
        const data = this._viewDatas.get(className);
        return data ? data.viewType : null;
    }

    /**
     * 获取类名
     * @param {string|function} type - 类型
     * @returns {string} - 类名
     */
    getClassName(type) {
        return typeof type === "string" ? type : cc.js.getClassName(type);
    }

    /**
     * 默认打开选项
     * @param {object} options - 选项
     * @returns {object} - 默认选项
     */
    moren_dakai_xuanxiang(options) {
        return {
            bundle: options.bundle || $macros.Macro.BUNDLE_RESOURCES,
            url: options.url,
            delay: options.delay,
            name: options.name,
            zIndex: options.zIndex || 0,
            preload: options.preload || false,
            type: options.type,
            args: options.args,
            showLoading: options.showLoading,
            showUILoading: options.showUILoading,
            shifou_yanchi_shifang_ziyuan: options.shifou_yanchi_shifang_ziyuan !== undefined ? options.shifou_yanchi_shifang_ziyuan : true
        };
    }

    /**
     * 预加载资源
     * @param {string} type - 资源类型
     * @param {string} bundle - 资源包
     * @param {string} url - 资源路径
     * @returns {Promise} - 预加载结果
     */
    preload(type, bundle, url) {
        return this.open({ type, preload: true, bundle, url });
    }

    /**
     * 解析预制体URL
     * @param {string} url - URL
     * @returns {object} - 解析结果
     */
    jiexi_yuzhiti_url(url) {
        return url[0] === "@"
            ? { isPrefab: false, url: url.substr(1) }
            : { isPrefab: true, url };
    }

    /**
     * 打开视图
     * @param {object} options - 打开选项
     * @returns {Promise} - 打开结果
     */
    open(options) {
        const opt = this.moren_dakai_xuanxiang(options);
        return this._open(opt);
    }

    /**
     * 内部打开视图
     * @param {object} options - 打开选项
     * @returns {Promise} - 打开结果
     */
    _open(options) {
        return new Promise((resolve) => {
            if (options.type) {
                const className = cc.js.getClassName(options.type);
                if (this.shitu_genjiedian) {
                    let viewData = this.huoqu_shitu_shuju(options.type);
                    if (viewData) {
                        viewData.isPreload = options.preload;
                        viewData.info.shifou_yanchi_shifang_ziyuan = options.shifou_yanchi_shifang_ziyuan;

                        if (viewData.isLoaded) {
                            viewData.status = ViewStatus.WAITTING_NONE;
                            if (!options.preload && viewData.view && cc.isValid(viewData.node)) {
                                viewData.node.zIndex = options.zIndex;
                                viewData.node.active = true;
                                if (!viewData.node.parent) {
                                    this.tianjia_shitu(viewData.node, options.zIndex);
                                }
                                viewData.view.params = options;
                                viewData.view.show(options.args);
                            }
                            resolve(viewData.view);
                        } else {
                            viewData.status = ViewStatus.WAITTING_NONE;
                            if (!options.preload) {
                                if (options.showLoading) {
                                    Manager.loading.show();
                                } else if (options.showUILoading) {
                                    Manager.ui_Loading.show({ uiName: options.name, delay: options.delay });
                                }
                            }
                            viewData.finishCb.push(resolve);
                        }
                    } else {
                        viewData = new ViewData();
                        viewData.loadData.name = className;
                        const url = options.url || options.type.huoqu_yuzhiti_url();
                        if (url) {
                            const prefabUrl = this.jiexi_yuzhiti_url(url);
                            viewData.isPreload = options.preload;
                            viewData.isPrefab = prefabUrl.isPrefab;
                            viewData.viewType = options.type;
                            viewData.bundle = options.bundle;
                            this._viewDatas.set(className, viewData);

                            if (!prefabUrl.isPrefab) {
                                viewData.info = new $resource.AL_Framewrok_Resource.Info();
                                viewData.info.url = prefabUrl.url;
                                viewData.info.type = cc.Prefab;
                                viewData.info.data = this.huoqu_changjing_yuzhiti(prefabUrl.url);
                                viewData.info.bundle = options.bundle;
                                viewData.info.shifou_yanchi_shifang_ziyuan = options.shifou_yanchi_shifang_ziyuan;
                                this.chuangjian_jiedian(viewData, resolve, options);
                            } else {
                                let loadProgress = null;
                                if (!options.preload) {
                                    if (options.showLoading) {
                                        Manager.loading.show();
                                    } else if (options.showUILoading) {
                                        Manager.ui_Loading.show({ uiName: options.name, delay: options.delay });
                                        loadProgress = (step, total) => {
                                            const progress = Math.ceil((step / total) * 100);
                                            Manager.ui_Loading.gengxin_jindu(progress);
                                        };
                                    }
                                }
                                this.jiazai_yuzhiti(options.bundle, url, loadProgress)
                                    .then((prefab) => {
                                        viewData.info = new $resource.AL_Framewrok_Resource.Info();
                                        viewData.info.url = url;
                                        viewData.info.type = cc.Prefab;
                                        viewData.info.data = prefab;
                                        viewData.info.bundle = options.bundle;
                                        viewData.info.shifou_yanchi_shifang_ziyuan = options.shifou_yanchi_shifang_ziyuan;
                                        Manager.assetManager.retainAsset(viewData.info);
                                        this.chuangjian_jiedian(viewData, resolve, options);
                                        if (options.showLoading) Manager.loading.hide();
                                        if (options.showUILoading) Manager.ui_Loading.hide();
                                    })
                                    .catch((error) => {
                                        viewData.isLoaded = true;
                                        Log.e(error);
                                        this.close(options.type);
                                        viewData.zhixing_suoyou_huidiao(null, className, "打开界面异常");
                                        resolve(null);
                                        if (options.showUILoading) Manager.ui_Loading.hide();
                                        if (options.showLoading) Manager.loading.hide();
                                    });
                            }
                        } else {
                            resolve(null);
                        }
                    }
                } else {
                    resolve(null);
                }
            } else {
                resolve(null);
            }
        });
    }

    /**
     * 创建节点并添加组件
     * @param {ViewData} viewData - 视图数据
     * @param {Function} resolve - 解决函数
     * @param {object} options - 选项
     */
    chuangjian_jiedian(viewData, resolve, options) {
        viewData.isLoaded = true;
        const className = this.getClassName(viewData.viewType);
        if (viewData.status === ViewStatus.WAITTING_CLOSE) {
            resolve(null);
            viewData.zhixing_suoyou_huidiao(null, className, "获取界面已关闭");
            return;
        }

        if (viewData.info.data instanceof cc.Node) {
            viewData.info.data.active = false;
        }

        const node = cc.instantiate(viewData.info.data);
        node.active = true;
        viewData.node = node;
        const component = this._tianjia_zujian(node, viewData, options);
        if (component) {
            if (viewData.status === ViewStatus.WATITING_HIDE) {
                component.hide();
                resolve(component);
                viewData.zhixing_suoyou_huidiao(component, className, "加载完成，但加载过程中被隐藏");
            } else {
                if (!viewData.isPreload) {
                    component.params = options;
                    component.show(options.args);
                }
                resolve(component);
                viewData.zhixing_suoyou_huidiao(component, className, "加载完成，回调之前加载中的界面");
            }
        } else {
            resolve(null);
        }
    }

    /**
     * 添加组件到节点
     * @param {cc.Node} node - 节点
     * @param {ViewData} viewData - 视图数据
     * @param {object} options - 选项
     * @returns {cc.Component} - 组件
     */
    _tianjia_zujian(node, viewData, options) {
        if (node) {
            const className = this.getClassName(viewData.viewType);
            let component = node.getComponent(viewData.viewType);
            if (!component) {
                component = node.addComponent(viewData.viewType);
            }
            if (component) {
                component.className = className;
                component.bundle = options.bundle;
                viewData.view = component;
                component.args = options.args;
                if (!viewData.isPreload) {
                    this.tianjia_shitu(node, options.zIndex);
                }
                return component;
            }
        }
        return null;
    }

    /**
     * 加载预制体
     * @param {string} bundle - 资源包
     * @param {string} url - 预制体URL
     * @param {Function} onProgress - 进度回调
     * @returns {Promise} - 加载结果
     */
    jiazai_yuzhiti(bundle, url, onProgress) {
        return new Promise((resolve, reject) => {
            Manager.assetManager.load({
                bundle,
                path: url,
                type: cc.Prefab,
                onProgress,
                onComplete: (result) => {
                    if (result && result.data && result.data instanceof cc.Prefab) {
                        resolve(result.data);
                    } else {
                        reject("加载prefab : " + url + " 失败");
                    }
                }
            });
        });
    }

    get shitu_genjiedian() {
        return cc.Canvas.instance.node;
    }

    get componentRoot() {
        if (!this._componentRoot || !cc.isValid(this._componentRoot)) {
            this._componentRoot = cc.find("componentRoot", this.canvas);
        }
        return this._componentRoot;
    }

    get mainController() {
        if (!this._mainController && !cc.isValid(this._mainController)) {
            const canvas = this.canvas;
            if (canvas) {
                this._mainController = canvas.getComponent("MainController");
            }
        }
        return this._mainController;
    }

    get prefabs() {
        if (!this._prefabs || !cc.isValid(this._prefabs)) {
            this._prefabs = cc.find("prefabs", this.canvas);
        }
        return this._prefabs;
    }

    huoqu_changjing_yuzhiti(url) {
        return cc.find(url);
    }

    onLoad(canvas) {
        this._canvas = canvas;
    }

    get canvas() {
        return this._canvas;
    }

    tianjia_shitu(node, zIndex) {
        this.shitu_genjiedian.addChild(node);
        if (typeof zIndex === "number") {
            node.zIndex = zIndex;
        }
    }

    tianjia_bendi(asset, owner) {
        if (asset) {
            const viewData = this.huoqu_shitu_shuju(owner);
            if (viewData) {
                viewData.loadData.tianjia_bendi(asset, owner);
            }
        }
    }

    tianjia_yuancheng(asset, owner) {
        if (asset) {
            const viewData = this.huoqu_shitu_shuju(owner);
            if (viewData) {
                viewData.loadData.tianjia_yuancheng(asset, owner);
            }
        }
    }

    close(type) {
        const viewData = this.huoqu_shitu_shuju(type);
        if (viewData) {
            viewData.status = ViewStatus.WAITTING_CLOSE;
            if (viewData.view && cc.isValid(viewData.node)) {
                viewData.node.removeFromParent();
                viewData.node.destroy();
            }
            this.chuli_ui_xiaohui(type);
        }
    }

    chuli_ui_xiaohui(type) {
        const viewData = this.huoqu_shitu_shuju(type);
        if (viewData) {
            const className = this.getClassName(type);
            viewData.loadData.clear();
            this._viewDatas.delete(className);
            Log.d(this._logTag + " close view : " + className);
        }
    }

    close_Except(exceptions) {
        const exceptionSet = new Set();
        exceptions.forEach((exception) => {
            exceptionSet.add(this.getClassName(exception));
        });
        this._viewDatas.forEach((viewData, className) => {
            if (!exceptionSet.has(className)) {
                this.close(className);
            }
        });
    }

    close_Bundle_View(bundle) {
        this._viewDatas.forEach((viewData, className) => {
            if (viewData.bundle === bundle) {
                this.close(className);
            }
        });
    }

    hide(type) {
        const viewData = this.huoqu_shitu_shuju(type);
        if (viewData) {
            if (viewData.isLoaded) {
                if (viewData.view && cc.isValid(viewData.view.node)) {
                    viewData.view.hide();
                }
            } else {
                viewData.status = ViewStatus.WATITING_HIDE;
            }
        }
    }

    huoqu_shitu(type) {
        return new Promise((resolve) => {
            const viewData = this.huoqu_shitu_shuju(type);
            if (viewData) {
                if (!viewData.isPreload) {
                    if (viewData.isLoaded) {
                        resolve(viewData.view);
                    } else {
                        viewData.getViewCb.push(resolve);
                    }
                } else {
                    resolve(null);
                }
            } else {
                resolve(null);
            }
        });
    }

    jiancha_shitu() {}

    isShow(type) {
        const viewData = this.huoqu_shitu_shuju(type);
        return viewData && viewData.isLoaded && viewStatus === ViewStatus.WAITTING_NONE && viewData.view && viewData.view.node.active;
    }

    addComponent(type) {
        const root = this.componentRoot;
        return root ? root.getComponent(type) || root.addComponent(type) : null;
    }

    removeComponent(type) {
        const root = this.componentRoot;
        if (root) {
            const component = root.getComponent(type);
            if (component) {
                component.destroy();
            }
        }
    }

    print(debugInfo) {
        if (debugInfo) {
            if (debugInfo.printViews) {
                this._viewDatas.forEach((viewData, viewName) => {
                    debugInfo.printViews(viewData, viewName);
                });
            }
            const rootNode = this.shitu_genjiedian;
            if (debugInfo.printChildren && rootNode) {
                rootNode.children.forEach(child => debugInfo.printChildren(child));
            }
            const componentRootNode = this.componentRoot;
            if (debugInfo.printComp && componentRootNode) {
                componentRootNode._components.forEach(component => debugInfo.printComp(component));
            }
        }
    }
}

exports.AL_Framework_UI_Manager = AL_Framework_UI_Manager;

// 单例模式
AL_Framework_UI_Manager._instance = null;

